<template>
	<view class="collect">
		<block v-if="list.length==0">
			<view class="kong">
				<view class="acea-row row-middle row-center none-t">
					<text class="fs-40 color666">暂无收藏服务呢~</text>
					<text class="color666 fs-32">点击前往首页收藏</text>
				</view>
			</view>
			<view class="back-btn" @click="home"></view>
		</block>
		
		<view class="list">
			<view class="item acea-row bor-bot pb30" v-for="(item,index) in list" :key="index">
				<view class="pictrue">
					<image class="imgwh" :src="item.image" mode="aspectFit"></image>
				</view>
				<view class="ml20">
					<view class="acea-row row-between">
						<view class="title line2 color333 fs-36 bold">{{ item.title }}</view>
						<view class="warn fs-30 mt10" v-if="item.is_show==0">已下架</view>
					</view>
					<view class="btn acea-row row-middle row-center" @click="cancel(item)">
						<text class="iconfont icon-shoucangxuanzhong"></text>
						<text>取消收藏</text>
					</view>
				</view>
			</view>
		</view>
		<view class='loadingicon acea-row row-center-wrapper' v-if='list.length > 0'>
			<text class='loading iconfont icon-jiazai' :hidden='loading==false'></text>{{loadTitle}}
		</view>

		<suspension></suspension>
	</view>
</template>

<script>
	import suspension from '@/components/suspension.vue';
	import{
		relationList,
		cancelcollect
	} from '@/api/admin.js'
	export default {
		components:{
			suspension
		},
		data() {
			return {
				page:1,
				limit:10,
				list:[],
				loadend: false,
				loading: false,
				loadTitle: this.$t(`加载更多`),
			};
		},
		onLoad() {
			this.getlist();
		},
		methods:{
			home(){
				uni.switchTab({
					url: '/pages/newIndex/index'
				})
			},
			cancel(item){
				let that = this;
				cancelcollect({ shop_id : item.id }).then(res=>{
					that.$util.Tips({ title : res.msg },()=>{
						that.loadend = false;
						that.loading = false;
						that.page = 1;
						that.list = [];
						that.getlist();
					})
				}).catch(err=>{ 
					that.$util.Tips({ title : err })
				})
			},
			getlist(){
				let that = this;
				if (that.loadend) return;
				if (that.loading) return;
				that.loading = true;
				that.loadTitle = '';
				relationList({ page:that.page,limit:that.limit }).then(res=>{
					let list = res.data.data;
					let arr = that.$util.SplitArray(list, that.list);
					let loadend = list.length < that.limit;
					that.loadend = loadend;
					that.loading = false;
					that.loadTitle = loadend ? that.$t(`没有更多内容啦~`) : that.$t(`加载更多`);
					that.$set(that, 'list', arr);
					that.$set(that, 'page', that.page + 1);
				}).catch(err=>{
					that.loading = false;
					that.loadTitle = that.$t(`加载更多`);
				})
			},
		},
		onReachBottom() {
			this.getlist();
		}
	}
</script>

<style lang="scss">
	.collect{
		
		.list{
			padding: 0 30rpx;
			
			.item{
				padding: 30rpx 0;
				position: relative;
				
				.title{
					width: 400rpx;
				}
				
				.pictrue{
					width: 170rpx;
					height: 170rpx;
					border-radius: 10rpx;
				}
				.btn{
					background: rgba(253, 125, 54, 0.2);
					width: 236rpx;
					height: 70rpx;
					border-radius: 35rpx;
					color: #FD7D36;
					position: absolute;
					bottom: 30rpx;
					right: 0;
					
					.iconfont{
						color: #FD7D36;
						font-size: 35rpx;
					}
				}
			}
			
		}
		
		.kong{
			width: 520rpx;
			height: 520rpx;
			background-image: url('https://yijiaan.oss-cn-hangzhou.aliyuncs.com/pic/none-icon.png');
			background-size: 100% 100%;
			margin: 30rpx auto;
			position: relative;
			
			.none-t{
				width: 100%;
				color: #888888;
				font-size: 34rpx;
				position: absolute;
				bottom: -20rpx;
				left: 0;
				right: 0;
			}
		}
		
		.back-btn{
			background-image: url('https://yijiaan.oss-cn-hangzhou.aliyuncs.com/pic/collect-btn.png');
			background-size: 100% 100%;
			width: 532rpx;
			height: 104rpx;
			margin: 100rpx auto;
		}
		
		
	}
</style>
